﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace EasyMvcBlog.Infrastructure
{
    public static class MD5Encrypt
    {
        /// <summary>
        /// MD5加密，不可逆
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string Encrypt(string text)
        {
            if (text == "")
            {
                return "";
            }

            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            return BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(text)), 6, 8);
        }

        /// <summary>
        /// MD5加密，不可逆
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string EncryptMD5(this String s)
        {
            if (s == "")
            {
                return "";
            }

            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            return BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(s)), 6, 8);
        }
    }
}
